package com.ptms.service.impl;

import com.ptms.dto.CampusSelectDTO;
import com.ptms.entity.Campus;
import com.ptms.repository.CampusRepository;
import com.ptms.service.CampusService;
import com.ptms.vo.ResultVO;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.stream.Collectors;

@Service
@RequiredArgsConstructor
public class CampusServiceImpl implements CampusService {

    private final CampusRepository campusRepository;

    @Override
    public ResultVO<List<CampusSelectDTO>> getAllCampuses() {
        // 查询所有校区并转换为DTO（只返回ID、名称、地址）
        List<CampusSelectDTO> campusList = campusRepository.findAll().stream()
                .map(campus -> {
                    CampusSelectDTO dto = new CampusSelectDTO();
                    dto.setId(campus.getId());
                    dto.setName(campus.getName());
                    dto.setAddress(campus.getAddress());
                    return dto;
                })
                .collect(Collectors.toList());
        return ResultVO.success(campusList);
    }
}